
Ext.define('PackageManager.view.PackageView', {
    extend: 'Ext.grid.Panel',
    alias: 'widget.packageview',
    title: 'Package Manager',
    store: 'ComponentStore',
    width: 500,
    id: 'griddy',

    columns: [
        {
            text: '<b>Label</b>',
            dataIndex: 'label',
            tdCls: 'label',
            id: 'label',
            flex: 3
        },
        {
            text: 'EXIST',
            dataIndex: 'existsValue',
            flex: 2,
            tdCls: 'exist',
            id: 'existColumn'

        },
        {
            text: 'FINAL',
            dataIndex: 'finalValue',
            tdCls: 'cells',
            id: 'finalColumn'

        }
    ],
    plugins: [
        Ext.create('Ext.grid.plugin.CellEditing', {
            clicksToEdit: 1
        })
    ],


    chooseState: function () {
        console.log('xxx');

        if (Ext.getStore('PackageStore').getAt(0) == null) {
            return false;
        }


        var dataStage = Ext.getStore('PackageStore').getAt(0).data.stage;
        var existColumn = Ext.getCmp('existColumn');
        var finalColumn = Ext.getCmp('finalColumn');
        console.log('Stage: ' + dataStage);

        this.setTitle('Current stage: ' + dataStage);

        console.log('title ' + this.title);

        if (dataStage == 'PRE_COMMITTEE') {
            existColumn.editor = this.comboPack();
            existColumn.tdCls = 'cells ' + existColumn.getEditor().getValue();
            finalColumn.hide();


        } else if (dataStage == 'IN_COMMITTEE') {
            console.log(Ext.getStore('PackageStore').getAt(0).data.stage);
            finalColumn.show();
            existColumn.setEditor(null);
            existColumn.tdCls = '';
            finalColumn.editor = this.comboPack();
        }

        this.getView().refresh();


    },


    comboPack: function () {
        var comboEdit = new Ext.form.ComboBox({
            queryMode: 'local',
            store: 'StaticDataStore',
            cls:'supereditor',
            pluginId: 'finalEdit',
            displayField: 'label',
            editable: false,
            listConfig: {
                componentCls: 'editorList'
            },
            listeners: {
                beforequery: function (qe) {
                    console.log('beforequery');
                    var varFilter = this.up().up().getSelectionModel().getSelection()[0].getData().staticData;
                    qe.combo.store.clearFilter(true);
                    qe.combo.store.filter([
                        {
                            filterFn: function (item) {
                                return item.get("staticDataSet") == varFilter;
                            }
                        }
                    ]);

                },
                focus: function () {
                    this.doQuery('');
                    this.expand();
                },
                select: function(){
                    this.triggerBlur();

                }
            }
        });
        return comboEdit;
    }
})
;